<?php
class MailUtility
{
    public static function send($to, $subject, $view, $data = array(), $layout = null)
    {
        // config server
        $serverInfo = Yii::app()->params[ENUM_CONFIG_PARAM_MAIL_SERVER];

        // send mail
        $mail = new YiiMailer();
        $mail->clearLayout();
        if($layout)
        {
            $mail->setLayout($layout);
        }
        $mail->setFrom(CONST_MAIL_FROM_ADDRESS, CONST_MAIL_FROM_NAME);
        $mail->setTo($to);
        $mail->setSubject($subject);
        $mail->setView($view);
        $mail->setData($data);
        $mail->IsSMTP();
        $mail->Host = $serverInfo['host'];
        $mail->Port = $serverInfo['port'];
        $mail->SMTPAuth = true;
        $mail->Username = $serverInfo['username'];
        $mail->Password = $serverInfo['password'];
        $mail->SMTPSecure = $serverInfo['encryption'];
        return $mail->send();
    }
}
